package demo15_2;

import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class Test15_2 {
    public static void main(String[] args) {
        List<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        System.out.println(list);

        for (int x:list) {
            System.out.print(x+" ");
        }
        System.out.println();

        ListIterator<Integer> it = list.listIterator();
        while (it.hasNext()) {
            System.out.print(it.next()+" ");
        }
        System.out.println();

        ListIterator<Integer> it1 = list.listIterator(list.size());
        while (it1.hasPrevious()) {
            System.out.print(it1.previous()+" ");
        }
        System.out.println();
    }
    public static void main1(String[] args) {
        MyLinkedList myLinkedList = new MyLinkedList();
        myLinkedList.createLinkedList();
        myLinkedList.addLast(999);
        myLinkedList.display();
        myLinkedList.clear();
        myLinkedList.display();

        MyLinkedList myLinkedList1 = new MyLinkedList();
        myLinkedList1.addFirst(15);
        myLinkedList1.addLast(16);
        myLinkedList1.addLast(45);
        myLinkedList1.addLast(78);
        myLinkedList1.display();
        myLinkedList1.addIndex(3,888);
        myLinkedList1.addIndex(2,999);
        myLinkedList1.display();//15 16 999 45 888 78
        myLinkedList1.remove(1);
        myLinkedList1.remove(15);
        myLinkedList1.display();
        myLinkedList1.remove(78);
        myLinkedList1.display();
        myLinkedList1.remove(45);
        myLinkedList1.display();
        myLinkedList1.remove(16);
        myLinkedList1.remove(999);
        myLinkedList1.display();
        myLinkedList1.remove(888);
        myLinkedList1.display();

        MyLinkedList myLinkedList2 = new MyLinkedList();
        myLinkedList2.addFirst(1);
        myLinkedList2.addFirst(1);
        myLinkedList2.addFirst(1);
        myLinkedList2.addFirst(1);
        myLinkedList2.addFirst(1);
        myLinkedList2.display();
        myLinkedList2.removeAllKey(1);
        myLinkedList2.display();
    }
}
